﻿//增加数据的提交函数（父页面刷新）
var t = true;
function autoSubmit(controllerName, actionAddName, actionListName) {
    var postData = $("#Form").formSerialize();
    var url = "/" + controllerName + "/" + actionAddName;
    var options = {
        type: 'POST',
        data: postData,
        dataType: 'json',
        url: url,
        async: false,
        cache: false,
        success: function (msg) {
            if (msg.Status) {
                parent.layer.msg('添加成功！', { icon: 1, time: 700 }, function () {
                    window.parent.location.reload(true);
                });
            } else {
                if (msg.Message != null) {
                    parent.layer.msg(msg.Message, { icon: 2 });
                } else {
                    parent.layer.msg('登陆超时，请重新登录', { icon: 2 });
                }
            }
        }, error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log(XMLHttpRequest.status);
            console.log(XMLHttpRequest.readyState);
            console.log(textStatus);
        },
    }

    if ($("#Form").validate().form()) {
        if (t) {
            t = false;
            $.ajax(options);
            t = true;
        }
    }
};
//增加数据的提交函数(本页面刷新)
var tt = true;
function autoSubmits(controllerName, actionAddName, actionListName) {
    var postData = $("#Form").formSerialize();
    var url = "/" + controllerName + "/" + actionAddName;
    var options = {
        type: 'POST',
        data: postData,
        url: url,
        async: false,
        cache: false,
        success: function (msg) {
            if (msg.Status) {
                layer.msg('添加成功！', { icon: 1, time: 700 }, function () {
                    window.location.reload(true);
                });
            } else {
                if (msg.Message != null) {
                    layer.msg(msg.Message, { icon: 2 });
                } else {
                    layer.msg('登陆超时，请重新登录', { icon: 2 });
                }
            }
        }
    }
    if ($("#Form").validate().form()) {
        if (tt) {
            tt = false;
            $.ajax(options);
            tt = true;
        }
    }
};
//编辑数据提交（父页面刷新）
var te = true;
function EditSubmit(controllerName, actionEditName, actionListName) {
    var postData = $("#Form").formSerialize();
    var url = "/" + controllerName + "/" + actionEditName;
    var options = {
        type: 'POST',
        data: postData,
        url: url,
        async: false,
        cache: false,
        success: function (msg) {
            if (msg.Status) {
                parent.layer.msg('编辑成功！', { icon: 1, time: 700 }, function () {
                    window.parent.location.reload(true);

                });
            } else {
                if (msg.Message != null) {
                    parent.layer.msg(msg.Message, { icon: 2 });
                } else {
                    parent.layer.msg('登陆超时，请重新登录', { icon: 2 });
                }
            }
        }
    };
    if ($("#Form").validate().form()) {
        if (te) {
            te = false;
            $.ajax(options);
            te = true;
        }
    }
};
//编辑数据提交（子页面刷新）
var tte = true;
function EditSubmits(controllerName, actionEditName, actionListName) {
    var postData = $("#Form").formSerialize();
    var url = "/" + controllerName + "/" + actionEditName;
    var options = {
        type: 'POST',
        data: postData,
        url: url,
        async: false,
        cache: false,
        success: function (msg) {
            if (msg.Status) {
                layer.msg('编辑成功！', { icon: 1, time: 700 }, function () {
                    window.location.reload(true);

                });
            } else {
                if (msg.Message != null) {
                    layer.msg(msg.Message, { icon: 2 });
                } else {
                    layer.msg('登陆超时，请重新登录', { icon: 2 });
                }
            }
        }
    };
    if ($("#Form").validate().form()) {
        if (tte) {
            tte = false;
            $.ajax(options);
            tte = true;
        }
    }
};
function NextSubmit(frmId) {
    $("#Form_" + num).ajaxSubmit(function (e) {
        if (!msg.Status) {
            $.error(msg.Message, '提示');
        }
    });
}

//编辑数据提交后，跳转到指定的地址
//paramArr[{key:"",value:""}]
function EditSubmitWithParams(controllerName, actionEditName, actionListName, paramKeys, paramValues) {
    var postData = $("#Form").formSerialize();
    var url = "/" + controllerName + "/" + actionEditName;
    var options = {
        type: 'POST',
        data: postData,
        url: url,
        async: false,
        cache: false,
        success: function (msg) {
            if (msg.Status) {
                if (paramKeys != undefined && paramValues != undefined) {
                    var paramStr = "";
                    var paramKeyArr = paramKeys.split(','),
                        paramValueArr = paramValues.split(',');
                    for (var i = 0; i < paramKeyArr.length; i++) {
                        if (i == 0) {
                            paramStr += ("?" + paramKeyArr[i] + "=" + paramValueArr[i]);
                        }
                        else {
                            paramStr += ("&" + paramKeyArr[i] + "=" + paramValueArr[i]);
                        }
                    }
                    $.success(msg.Message, '提示', function () { window.location.href = "/" + controllerName + "/" + actionListName + paramStr; });
                }
                else {
                    $.success(msg.Message, '提示', function () { window.location.href = "/" + controllerName + "/" + actionListName });
                }
            }
            else {
                $.error(msg.Message, '提示');
            }
        }
    };
    if ($("#Form").validate().form()) {
        if (te) {
            te = false;
            $.ajax(options);
            te = true;
        }
    }
}

function submitForm() {
    var loading = $(window.parent.document).find("#load");
    loading.show();
    $("#Form").submit();

    //var hideLoading = $(window.parent.document).find("#load");
    //hideLoading.hide();

}

//弹出模式窗口
function AlertModelFrame(url, modelTitle) {
    layer.open({
        type: 2, //page层,1自定义html，2页面层
        title: modelTitle,
        shade: 0.3,  //遮罩透明度，默认0.3
        moveType: 0, //拖拽风格，0是默认，1是传统拖动
        shift: 0,    //0-6的动画形式，0是默认，-1不开启
        maxmin: false,  //开启最大化按钮
        area: ['500px', '400px'],
        content: url
    });
};
function AlertModelFrameNew(url, modelTitle, width, high) {
    layer.open({
        type: 2, //page层,1自定义html，2页面层
        title: modelTitle,
        shade: 0.3,  //遮罩透明度，默认0.3
        moveType: 0, //拖拽风格，0是默认，1是传统拖动
        shift: 0,    //0-6的动画形式，0是默认，-1不开启
        maxmin: false,  //开启最大化按钮
        area: [width + 'px', high + 'px'],
        content: url
    });
}

//跳转到指定的地址
function GoPage(url) {
    window.location.href = url;
}

//后退
function goBack() {
    try {
        var referurl;
        referurl = document.referrer;
        window.location.href = referurl;
    } catch (e) {
        history.go(-1);
    }
}

//取消、关闭弹出层
function CloseModelFrame() {
    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    parent.layer.close(index); //再执行关闭 
    //layer.closeAll();
}

//跳转到指定的地址
//paramArr[{key:"",value:""}]
function GoPageWithParamArr(url, paramKeys, paramValues) {
    var paramStr = "";
    if (paramKeys == undefined || paramValues == undefined) {
        window.location.href = url;
        return;
    }
    var paramKeyArr = paramKeys.split(','),
        paramValueArr = paramValues.split(',');
    for (var i = 0; i < paramKeyArr.length; i++) {
        if (i == 0) {
            paramStr += ("?" + paramKeyArr[i] + "=" + paramValueArr[i]);
        }
        else {
            paramStr += ("&" + paramKeyArr[i] + "=" + paramValueArr[i]);
        }
    }
    window.location.href = url + paramStr;
}

//格式化日期， 参数：date ：new Date()后的日期，format:格式，如“YYYY年MM月DD日 hh时mm分ss秒”
function formatDate(date, format) {
    if (arguments.length < 2 && !date.getTime) {
        format = date;
        date = new Date();
    }
    typeof format != 'string' && (format = 'YYYY年MM月DD日 hh时mm分ss秒');
    var week = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', '日', '一', '二', '三', '四', '五', '六'];
    return format.replace(/YYYY|YY|MM|DD|hh|mm|ss|星期|周|www|week/g, function (a) {
        switch (a) {
            case "YYYY": return date.getFullYear();
            case "YY": return (date.getFullYear() + "").slice(2);
            case "MM": return date.getMonth() + 1;
            case "DD": return date.getDate();
            case "hh": return date.getHours();
            case "mm": return date.getMinutes();
            case "ss": return date.getSeconds();
            case "星期": return "星期" + week[date.getDay() + 7];
            case "周": return "周" + week[date.getDay() + 7];
            case "week": return week[date.getDay()];
            case "www": return week[date.getDay()].slice(0, 3);
        }
    });
}

Date.prototype.format = function (format) {
    var o = {
        "M+": this.getMonth() + 1, //month
        "d+": this.getDate(),    //day
        "h+": this.getHours(),   //hour
        "m+": this.getMinutes(), //minute
        "s+": this.getSeconds(), //second
        "q+": Math.floor((this.getMonth() + 3) / 3),  //quarter
        "S": this.getMilliseconds() //millisecond
    }
    if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
    (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o) if (new RegExp("(" + k + ")").test(format))
        format = format.replace(RegExp.$1,
        RegExp.$1.length == 1 ? o[k] :
        ("00" + o[k]).substr(("" + o[k]).length));
    return format;
}

//json格式的日期
function GetTimeFromJsonString(jsonTime) {
    var re = /-?\d+/;
    var m = re.exec(jsonTime);
    var d = new Date(parseInt(m[0]));
    return d;
}

//获取等级划分线
function getPlotLines(pollutantName) {
    var plotLines;
    if (pollutantName === "AQI") {
        plotLines = [{
            value: 50,
            color: '#00FF00',
            width: 3,
            label: {
                text: '一级',
                align: 'left',
                style: {
                    color: 'gray'
                }
            }
        }, {
            value: 100,
            color: '#FFFF00',
            width: 3,
            label: {
                text: '二级',
                align: 'left',
                style: {
                    color: 'gray'
                }
            }
        }, {
            value: 150,
            color: '#FF7E00',
            width: 3,
            label: {
                text: '三级',
                align: 'left',
                style: {
                    color: 'gray'
                }
            }
        }, {
            value: 200,
            color: '#FF0000',
            width: 3,
            label: {
                text: '四级',
                align: 'left',
                style: {
                    color: 'gray'
                }
            }
        }, {
            value: 300,
            color: '#99004C',
            width: 3,
            label: {
                text: '五级',
                align: 'left',
                style: {
                    color: 'gray'
                }
            }
        }];
    }
    else if (pollutantName == "PM2_5") {
        plotLines = [{
            value: 75,
            color: '#FFFF00',
            width: 3,
            label: {
                text: '二级标准线',
                align: 'left',
                style: {
                    color: 'gray'
                }
            }
        }];
    }
    else if (pollutantName == "PM10") {
        plotLines = [{
            value: 150,
            color: '#FFFF00',
            width: 3,
            label: {
                text: '二级标准线',
                align: 'left',
                style: {
                    color: 'gray'
                }
            }
        }];
    }
    else if (pollutantName == "SO2") {
        plotLines = [{
            value: 150,
            color: '#FFFF00',
            width: 3,
            label: {
                text: '二级标准线',
                align: 'left',
                style: {
                    color: 'gray'
                }
            }
        }];
    }
    else if (pollutantName == "NO2") {
        plotLines = [{
            value: 80,
            color: '#FFFF00',
            width: 3,
            label: {
                text: '二级标准线',
                align: 'left',
                style: {
                    color: 'gray'
                }
            }
        }];
    }
    else if (pollutantName == "CO") {
        plotLines = [{
            value: 4,
            color: '#FFFF00',
            width: 3,
            label: {
                text: '二级标准线',
                align: 'left',
                style: {
                    color: 'gray'
                }
            }
        }];
    }
    else if (pollutantName == "O3_8H") {
        plotLines = [{
            value: 160,
            color: '#FFFF00',
            width: 3,
            label: {
                text: '二级标准线',
                align: 'left',
                style: {
                    color: 'gray'
                }
            }
        }];
    }
    return plotLines;
}

//图片自适应容器
function autoResizeImage(container) {
    var img = $("#" + container).find("img");
    var maxWidth = $("#" + container).width();
    var maxHeight = $("#" + container).height();
    var width = img.width();
    var height = img.height();
    var wRatio = maxWidth / width;
    var hRatio = maxHeight / height;
    var ratio = Math.min(wRatio, hRatio);
    width = Math.round(ratio * width);
    height = Math.round(ratio * height);
    img.css("width", width);
    img.css("height", height);
    img.show();
}

//新窗口浏览图片
//function openNew(e) {
//    var evt = e ? e : (window.event ? window.event : null); //此方法为了在firefox中的兼容
//    var currentImg = evt.srcElement ? evt.srcElement : evt.target; //evt.target在火狐上才能识别用的。
//    currentImg = $(currentImg);
//    var re = new RegExp("\\\\", "g");
//    var currentImgSrc = currentImg.attr("src").replace("..", "");
//    currentImgSrc = currentImgSrc.replace(re, '/');
//    currentImgSrc = currentImgSrc.replace(new RegExp(/(-)/g), '|');     //适应新的图片接口
//    var imgStr = "";
//    var imgInputs = $(".ul-4").find("input[name='ImageSrc']");

//    $.each(imgInputs, function (index, input) {
//        var src = input.value;
//        src = src.replace("..", "");
//        src = src.replace(re, '/');
//        src = src.replace(new RegExp(/(-)/g), '|');              //适应新的图片接口
//        //imgStr = isReverse ? src + "-" + imgStr : imgStr + src + "-";
//        imgStr += src + "-";
//    });
//    var url;
//    var reg = new RegExp("http://202.104.69.203:8091/WeatherImage1", "g");
//    imgStr = imgStr.replace(reg, 'DOMAIN');

//    if (imgStr.indexOf("SurfaceAirPressure") >= 0) {    //该类型图片的参数太长，用特定字符替换部分字符串已达到缩短请求参数长度的目的
//        var reg = new RegExp("/SpiPictrue/WeatherSituation/SurfaceAirPressure/", "g");
//        imgStr = imgStr.replace(reg, '(');
//        //url = "/Weather/ImageGallery/?imgStr=" + imgStr + "&currentImgStr=" + currentImgSrc + "&oldStr=(&newStr=/SpiPictrue/WeatherSituation/SurfaceAirPressure/";
//        url = "imgStr=" + imgStr + "&currentImgStr=" + currentImgSrc + "&oldStr=(&newStr=/SpiPictrue/WeatherSituation/SurfaceAirPressure/";
//    }
//    else {
//        //url = "/Weather/ImageGallery/?imgStr=" + imgStr + "&currentImgStr=" + currentImgSrc;
//        url = "imgStr=" + imgStr + "&currentImgStr=" + currentImgSrc;
//    }

//    url += "&joinDomain=DOMAIN";
//    DelCookie("imgUrl");  //清除cookie
//    //document.cookie = "imgUrl=imgStr=http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000000000.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000000300.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000000600.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000000900.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000001200.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000001500.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000001800.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000002100.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000002400.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000002700.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000003000.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000003300.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000003600.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000003900.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000004200.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000004500.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000004800.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000005100.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000005400.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000005700.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000006000.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000007200.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000008400.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000009600.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000010800.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000012000.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000013200.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000014400.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000015600.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000016800.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000019200.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000021600.JPG-http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000024000.JPG-&currentImgStr=http://202.104.69.202:18400/PictureDataPath/中央气象台|T639L60图|00/T639L60|高度场|00/2015|10|09/SEVP_NMC_NWPR_ST639_EGH_AEA_L50_P9_20151009000000000.JPG&joinDomain=DOMAIN"
//    //document.cookie = "imgUrl=" + encodeURI(url);   //设置cookie
//    //window.open("/Weather/GalleryDisplay", 'newwindow', 'height=520px,width=917px,top=' + modalTop + ',left=' + modalLeft + ',toolbar=no,menubar=no,scrollbars=no,Resizable=no,titlebar=no,location=no,status=no');
//    OpenWindowWithPost("/Weather/GalleryDisplay", "newWindow", url);
//}

function openNew(isReverse) {
    var currentImgInput = $(".ul-4 a.hov > input")[0];
    var imgStr = "";
    var re = new RegExp("\\\\", "g");
    var imgInputs = $(".ul-4").find("input[name='ImageSrc']");
    var length = imgInputs.length;
    var imgInputsNew, imgInputsTemp;
    for (var i = 0; i < length; i++) {
        if (imgInputs[i] == currentImgInput) {
            if (isReverse) {
                imgInputsNew = imgInputs.slice(i + 1, length);
                imgInputsTemp = imgInputs.slice(0, i + 1);
            }
            else {
                imgInputsNew = imgInputs.slice(i, length);
                imgInputsTemp = imgInputs.slice(0, i);
            }
        }
    }
    $.merge(imgInputsNew, imgInputsTemp);
    if (isReverse) {
        for (var i = length - 1; i > -1; i--) {
            var src = imgInputsNew[i].value;
            src = src.replace("..", "");
            src = src.replace(re, '/');
            imgStr += src + "*";
        }
    }
    else {
        for (var i = 0; i < length; i++) {
            var src = imgInputsNew[i].value;
            src = src.replace("..", "");
            src = src.replace(re, '/');
            imgStr += src + "*";
        }
    }
    //var reg = new RegExp("http://10.10.10.12:8085/File/DownloadForecastImage?filePath=", "g");
    //imgStr = imgStr.replace(reg, 'DOMAIN');


    //url += "&joinDomain=DOMAIN";
    DelCookie("imgUrl");  //清除cookie
    OpenWindowWithPost("/ImageShow/GalleryDisplay", "newWindow", imgStr);
}

function SetCookie(name, value) {//两个参数，一个是cookie的名子，一个是值 
    var Days = 1; //此 cookie 将被保存 1 天 
    var exp = new Date();    //new Date("December 31, 9998"); 
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + encodeURI(value) + ";expires=" + exp.toGMTString();
}

function GetCookie(name) {    //取cookies函数
    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if (arr != null) return unescape(arr[2]);
    return null;
}

function DelCookie(name) {  //删除cookie 
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = GetCookie(name);
    if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}

//新窗口浏览图片
function openNewPage(url, windowName) {
    window.open(url, 'windowName', 'top=0,left=0,toolbar=no,menubar=no,scrollbars=no,resizable=no,titlebar=no,location=no,status=no');
}

function OpenWindowWithPost(url, name, data) {
    var form = document.createElement("form");
    form.setAttribute("method", "post");
    form.setAttribute("action", url);
    form.setAttribute("target", name);
    if (data) {
        var input = document.createElement("input");
        input.type = "hidden";
        input.name = "hdnImgUrl";
        input.value = data;
        form.appendChild(input);
    }
    document.body.appendChild(form);
    window.open("_blank", name, 'height=540px,width=960px,top=100,left=100,toolbar=no,menubar=no,scrollbars=no,Resizable=no,titlebar=no,location=no,status=no');
    form.submit();
    document.body.removeChild(form);
};

//设置cookie，值为分页的每页行数
$(document).ready(function () {
    $("div.each-page a").each(function () {
        $(this).click(function () {
            document.cookie = "PageSize" + "=" + escape($(this).text()) + ";path=/;";
        });
    });
    $(".table").delegate("tr", "mouseover", function () {
        $(this).addClass("tr_over");
    });
    $(".table").delegate("tr", "mouseout", function () {
        $(this).removeClass("tr_over");
    });
});

//增加数据的提交函数
var t = true;
function JsonSubmit(controllerName, actionAddName, actionListName) {
    var jsonStr = "[";
    var trs = $("#tbody tr");
    trs.each(function () {
        jsonStr += "{"
        $("input,textarea", this).each(function () {
            if ($(this).is("textarea")) {
                var name = $(this).attr("name");
                jsonStr += '"' + name.substr(0, name.length - 4) + '":' + '"' + $(this).val() + '",'
            }
            else {
                jsonStr += '"' + $(this).attr("name") + '":' + '"' + $(this).val() + '",'
            }
        });
        jsonStr = jsonStr.substring(0, jsonStr.lastIndexOf(","));
        jsonStr += "},"
    });
    jsonStr = jsonStr.substring(0, jsonStr.lastIndexOf(","));
    jsonStr += "]";
    jsonStr = encodeURIComponent(jsonStr);
    var postData = $("#Form").formSerialize();
    postData += "&json=" + jsonStr;
    var url = "/" + controllerName + "/" + actionAddName;
    var options = {
        type: 'POST',
        data: postData,
        url: url,
        async: false,
        cache: false,
        success: function (msg) {
            if (msg.Status) {
                $.confirm('添加成功，需要继续添加?', '确认', function (action) {
                    if (action == 'ok') {
                        window.location.reload(true);
                    }
                    else {
                        window.location.href = "/" + controllerName + "/" + actionListName
                    }
                });
            } else {
                $.error(msg.Message, '提示');
            }
        }
    }
    if ($("#Form").validate().form()) {
        if (t) {
            t = false;
            $.ajax(options);
            t = true;
        }
    }
};

//污染物下标转换
function pollutantNameSubTransform(pollutantName) {
    if (pollutantName == null) {
        return "—";
    }
    if (pollutantName.indexOf("PM2.5") >= 0) {
        pollutantName = pollutantName.replace("PM2.5", "PM<sub>2.5</sub>");
    }
    if (pollutantName.indexOf("PM2_5") >= 0) {
        pollutantName = pollutantName.replace("PM2_5", "PM<sub>2.5</sub>");
    }
    if (pollutantName.indexOf("PM10") >= 0) {
        pollutantName = pollutantName.replace("PM10", "PM<sub>10</sub>");
    }
    if (pollutantName.indexOf("O3") >= 0) {
        pollutantName = pollutantName.replace("O3", "O<sub>3</sub>");
    }
    if (pollutantName.indexOf("SO2") >= 0) {
        pollutantName = pollutantName.replace("SO2", "SO<sub>2</sub>");
    }
    if (pollutantName.indexOf("NO2") >= 0) {
        pollutantName = pollutantName.replace("NO2", "NO<sub>2</sub>");
    }
    //if (pollutantName.indexOf("_8H") >= 0) {
    //    pollutantName = pollutantName.replace("_8H", "/8H");
    //}
    return pollutantName;
}

//污染物等级标准线
var levelStandardLine = [{
    value: 50,
    color: '#00FF00',
    width: 3,
    label: {
        text: '一级',
        align: 'left',
        style: {
            color: 'gray'
        }
    }
}, {
    value: 100,
    color: '#FFFF00',
    width: 3,
    label: {
        text: '二级',
        align: 'left',
        style: {
            color: 'gray'
        }
    }
}, {
    value: 150,
    color: '#FF7E00',
    width: 3,
    label: {
        text: '三级',
        align: 'left',
        style: {
            color: 'gray'
        }
    }
}, {
    value: 200,
    color: '#FF0000',
    width: 3,
    label: {
        text: '四级',
        align: 'left',
        style: {
            color: 'gray'
        }
    }
}, {
    value: 300,
    color: '#99004C',
    width: 3,
    label: {
        text: '五级',
        align: 'left',
        style: {
            color: 'gray'
        }
    }
}];

var airIndexs = [{
    Level: "—",
    ChineseLevel: "—",
    Type: "—",
    Color: "—",
    InColor: "—",
    Unheathful: "—",
    Measure: "—",
    AImage: "—"
}, {
    Level: "I",
    ChineseLevel: "一级",
    Type: "优",
    Color: "green",
    InColor: "#C9FFCA",
    Unheathful: "空气质量令人满意，基本无空气污染",
    Measure: "各类人群可正常活动",
    AImage: "../Content/images/aqi1.png"
}, {
    Level: "II",
    ChineseLevel: "二级",
    Type: "良",
    Color: "yellow",
    InColor: "#FFFFDE",
    Unheathful: "空气质量可接受，但某些污染物可能对极少数异常敏感人群健康有较弱影响",
    Measure: "极少数异常敏感人群应减少户外活动",
    AImage: "../Content/images/aqi2.png"
}, {
    Level: "III",
    ChineseLevel: "三级",
    Type: "轻度污染",
    Color: "orange",
    InColor: "#F4E4D4",
    Unheathful: "易感人群症状有轻度加剧，健康人群出现刺激症状",
    Measure: "各类人群可正常活动",
    AImage: "../Content/images/aqi1.png"
}, {
    Level: "I",
    ChineseLevel: "一级",
    Type: "优",
    Color: "green",
    InColor: "#C9FFCA",
    Unheathful: "空气质量令人满意，基本无空气污染",
    Measure: "儿童、老年人及心脏病、呼吸系统疾病患者应减少长时间、高强度的户外锻炼",
    AImage: "../Content/images/aqi3.png"
}, {
    Level: "IV",
    ChineseLevel: "四级",
    Type: "中度污染",
    Color: "red",
    InColor: "#FFD6D7",
    Unheathful: "进一步加剧易感人群症状，可能对健康人群心脏、呼吸系统有影响",
    Measure: "儿童、老年人及心脏病、呼吸系统疾病患者应减少长时间、高强度的户外锻炼，一般人群适量减少户外活动",
    AImage: "../Content/images/aqi4.png"
}, {
    Level: "V",
    ChineseLevel: "五级",
    Type: "重度污染",
    Color: "purple",
    InColor: "#FAD5E7",
    Unheathful: "心脏病和肺病患者症状显著加剧，运动耐力降低，健康人群普遍出现症状",
    Measure: "老年人及心脏病、肺病患者应停留在室内，停止户外活动，一般人群减少户外活动",
    AImage: "../Content/images/aqi5.png"
}, {
    Level: "VI",
    ChineseLevel: "六级",
    Type: "严重污染",
    Color: "crimson",
    InColor: "#E9B2C1",
    Unheathful: "健康人运动耐受力降低，有明显强烈症状，提前出现某些疾病",
    Measure: "老年人和病人应当留在室内，避免体力消耗，一般人群应避免户外活动",
    AImage: "../Content/images/aqi6.png"
}];

function AirIndex(aqi) {
    if (aqi >= 0 && aqi <= 50) {
        return airIndexs[1];
    }
    if (aqi >= 51 && aqi <= 100) {
        return airIndexs[2];
    }
    if (aqi >= 101 && aqi <= 150) {
        return airIndexs[3];
    }
    if (aqi >= 151 && aqi <= 200) {
        return airIndexs[4];
    }
    if (aqi >= 201 && aqi <= 300) {
        return airIndexs[5];
    }
    if (aqi >= 301 && aqi <= 1000) {
        return airIndexs[6];
    }
    return airIndexs[0];
}

//预报方案
var forecastValidate = {
    "1": "000小时预报",
    "2": "024小时预报",
    "3": "048小时预报",
    "4": "072小时预报",
    "5": "096小时预报",
    "6": "120小时预报",
    "7": "144小时预报"
};


//预报模型
var forecastModel = {
    "0": "多模式择优",
    "1": "多元回归模型",
    "2": "同期回归模型",
    "3": "BP神经网络",
    //"4": "天气形势统计模型",
    "5": "聚类回归模型"
};



//预报数据
var tf = true;
var cityForecast = function (timePoint, forecastModelId, dataLevel, code, callBack) {
    var postData = { TimePoint: timePoint, ForecastModelId: forecastModelId, DataLevel: dataLevel, Code: code };
    var url = "/ForecastPubManage/ForecastInManual";
    var options = {
        type: 'POST',
        data: postData,
        url: url,
        async: true,
        cache: false,
        success: function (msg) {
            if (msg.Status) {
                $('#fullbg', parent.document).hide();
                $.success(msg.Message, '提示', function () {
                    callBack();
                });
            }
            else {
                $('#fullbg', parent.document).hide();
                $.error(msg.Message, '提示');
            }
        }
    }
    if (tf) {
        tf = false;
        $('#fullbg', parent.document).show();
        $.ajax(options);
        tf = true;
    }
}


function loadingShow() {
    var loading = $(window.parent.document).find("#load");
    loading.show();
}

function loadingHide() {
    var loading = $(window.parent.document).find("#load");
    loading.hide();
}


//value为空的处理
function nullValueTransfer(value) {
    if (value == null) {
        return "--";
    }
    else {
        if (value == "PM2_5") {
            value = "PM2.5";
        }
        return value;
    }
}



$(document).ready(function () {
    //全选
    $(".selectAllChk").click(function () {
        if ($(this).prop("checked")) {
            $(".selectAllChk").prop("checked", true);
            $(".check").each(function () {
                $(this).prop("checked", true);
            });
        }
        else {
            $(".selectAllChk").prop("checked", false);
            $(".check").each(function () {
                $(this).prop("checked", false);
            });
        }
    });
});
//验证AQI的值是否符合规范
function checkAQILevel(lowId, highId, levelId, aqiLevelId) {
    var r = /^[0-9]*[1-9][0-9]*$/;　　//正整数
    var low = parseInt($(lowId).val());
    var high = parseInt($(highId).val());
    if (r.test(low) == false || r.test(high) == false || low > 500 || high > 500) {
        layer.alert('AQI范围值只能输入不大于500的正整数', { icon: 5 });
        $(levelId).val(null);
        return false;
    }
    if (isNaN(high) == false) {
        if (low >= high) {
            layer.alert('AQI低值不能大于或等于AQI高值', { icon: 5 });
            return false;
        }
        if (low <= 200) {
            if (high - low <= 30) {
                getLevelByHighValue(low, high, levelId, aqiLevelId);
            }
            else {
                layer.alert('中度污染及以下预报精度误差不得超过30！', { icon: 5 });
                $(levelId).val(null);
            }
        }
        else {
            if (high - low <= 60) {
                getLevelByHighValue(low, high, levelId, aqiLevelId);
            }
            else {
                layer.alert('中度污染以上预报精度误差不得超过60！', { icon: 5 });
                $(levelId).val(null);
            }
        }
    }
    else {
        getLevelByLowValue(low, levelId, aqiLevelId);
    }

};
//验证AQI范围、AQI等级、首要污染物
function checkAQI(aqiLow, aqiHigh, aqiLevel, primaryPollutant) {
    var r = /^[0-9]*[1-9][0-9]*$/;　　//正整数
    var low = parseInt($(aqiLow).val());
    var high = parseInt($(aqiHigh).val());
    var lever = $(aqiLevel).val();
    var primarypollutant = $(primaryPollutant).val();
    if (r.test(low) == false || r.test(high) == false || low > 500 || high > 500) {
        layer.alert('AQI范围值只能输入不大于500的正整数', { icon: 5 });
        return false;
    }
    if (low >= high) {
        layer.alert('AQI低值不能大于或等于AQI高值', { icon: 5 });
        return false;
    }
    if (low <= 200) {
        if (high - low > 30) {
            layer.alert('中度污染及以下预报AQI误差不得超过30！', { icon: 5 });
            return false;
        }
    }
    else {
        if (high - low > 60) {
            layer.alert('中度污染以上预报AQI误差不得超过60！', { icon: 5 });
            return false;
        }
    }
    if (lever != "优") {//当AQI等级不为优时，要有首要污染物
        if (primarypollutant.replace(/(^s*)|(s*$)/g, "").length == 0 || primarypollutant == "—") {
            layer.alert('AQI等级不为优时请选择首要污染物', { icon: 5 });
            return false;
        }
    }
    else {//当AQI等级为优时，不能有首要污染物
        if (primarypollutant.replace(/(^s*)|(s*$)/g, "").length != 0 && primarypollutant != "—") {
            layer.alert('AQI等级为优时不能有首要污染物', { icon: 5 });
            return false;
        }
    }
    return true;
}



function getLevelByLowValue(value, levelId, aqiLevelId) {
    var level = "";
    if (value > 0) {
        if (value <= 50) {
            level = "优";
        }
        else if (value <= 100) {
            level = "良";
        }
        else if (value <= 150) {
            level = "轻度污染";
        }
        else if (value <= 200) {
            level = "中度污染";
        }
        else if (value <= 300) {
            level = "重度污染";
        }
        else if (value >= 301) {
            level = "严重污染";
        }
        $(levelId).val(level);
        if (level == "优") {
            $(aqiLevelId).val("—");
        }
    }
}
function getLevelByHighValue(low, high, levelId, aqiLevelId) {
    var level = "";
    if (low > 0) {
        if (low <= 50 && high <= 50) {
            level = "优";
        }
        else if (low <= 50 && high <= 100) {
            level = "优~良";
        }
        else if (low <= 100 && high <= 100) {
            level = "良";
        }
        else if (low <= 100 && high <= 150) {
            level = "良~轻度污染";
        }
        else if (low <= 150 && high <= 150) {
            level = "轻度污染";
        }
        else if (low <= 150 && high <= 200) {
            level = "轻度污染~中度污染";
        }
        else if (low <= 200 && high <= 200) {
            level = "中度污染";
        }
        else if (low <= 200 && high <= 300) {
            level = "中度污染~重度污染";
        }
        else if (low >= 201 && high <= 300) {
            level = "重度污染";
        }
        else if (low <= 300 && high >= 301) {
            level = "重度污染~严重污染";
        }
        else if (low >= 301 && high >= 301) {
            level = "严重污染";
        }
        $(levelId).val(level);
        if (level == "优") {
            $(aqiLevelId).val("—");
        }
        else {
            if ($(aqiLevelId).val() == "—" || $(aqiLevelId).val() == "") {
                layer.alert('AQI等级不为优时请选择首要污染物', { icon: 5 });
            }
        }
    }
};
function tip(id) {
    layer.tips('1、优、良、轻度、中度范围，AQI预报区间不得超过30。<br />2、重度、严重范围，AQI预报区间不得超过60。<br />3、AQI等级自动生成。', id,
         {
             tips: [2, '#1396DE'],
             time: 5000,
         });
};